<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2024/5/13
  Time: 下午9:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.Connection,java.sql.Statement,java.sql.ResultSet,java.sql.DriverManager" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>eightShow</title>
    <link rel="stylesheet" href="../../css/table.css">
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    String ct = request.getParameter("content").trim();
    String sb = request.getParameter("submit").trim();
    if ((sb.contains("姓名") || sb.contains("学号")) && ct.isEmpty()) {
        response.sendRedirect("eight.jsp");
        return;
    }
    try {
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/Student", "root", "123456");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("select * from s where " + (sb.contains("姓名") ? "name" : "id") + "='" + ct + "'");
        if (rs.next())
            for (int i = 0; i < 4; i++)
                out.print((i == 0 ? "<table><tr><th>学号</th><th>姓名</th><th>数学</th><th>英语</th></tr>" : "") + "<td>" + rs.getString(i + 1) + "</td>" + (i == 3 ? "</tr></table>" : ""));
        conn.close();
    } catch (Exception e) {
        out.print(e.getMessage());
    }
%>
</body>
</html>
